home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / ds5000.md / devDC7085.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  23.0 KB  |  933 lines

  1. /* 
  2.  *  devDC7085.c --
  3.  *
  4.  *         This file contains machine-dependent routines that handle the
  5.  *    output queue for the serial lines.
  6.  *
  7.  *    Copyright (C) 1989 Digital Equipment Corporation.
  8.  *    Permission to use, copy, modify, and distribute this software and
  9.  *    its documentation for any purpose and without fee is hereby granted,
  10.  *    provided that the above copyright notice appears in all copies.  
  11.  *    Digital Equipment Corporation makes no representations about the
  12.  *    suitability of this software for any purpose.  It is provided "as is"
  13.  *    without express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/dev/ds5000.md/RCS/devDC7085.c,v 1.2 90/12/18 10:35:22 jhh Exp $ SPRITE (DECWRL)";
  18. #endif not lint
  19.  
  20. #include "sprite.h"
  21. #include "machMon.h"
  22. #include "mach.h"
  23. #include "dev.h"
  24. #include "fs.h"
  25. #include "sys.h"
  26. #include "sync.h"
  27. #include "timer.h"
  28. #include "dbg.h"
  29. #include "dc7085.h"
  30. #include "graphics.h"
  31. #include "machAddrs.h"
  32. #include "console.h"
  33. #include <sgtty.h>
  34.  
  35. static Sync_Semaphore dc7085Mutex = Sync_SemInitStatic("Dev:dc7085Mutex");
  36.  
  37. /*
  38.  * Define the six registers.
  39.  */
  40. #define REG_ADDR(offset) (unsigned short *)(MACH_DZ_ADDR + (offset))
  41. static volatile unsigned short *csrPtr =  REG_ADDR(0x00);
  42. static volatile unsigned short *rBufPtr = REG_ADDR(0x08);
  43. static volatile unsigned short *lprPtr =  REG_ADDR(0x08);
  44. static volatile unsigned short *tcrPtr =  REG_ADDR(0x10);
  45. static volatile unsigned short *msrPtr =  REG_ADDR(0x18);
  46. static volatile unsigned short *tdrPtr =  REG_ADDR(0x18);
  47.  
  48. /*
  49.  * The current status of the break bits.
  50.  */
  51. unsigned breakVal = 0;
  52.  
  53. /*
  54.  * Tables mapping sgttyb baud-rate values to actual integers and lpr register
  55.  * values.
  56.  */
  57. static struct {
  58.     int regVal;                /* Value to set in lpr register. */
  59.     int sgttybVal;            /* Baud value from sgtyb. */
  60.     int baud;                /* Integer baud rate. */
  61. } baudMap[] = {
  62.     {0, 0, 0},
  63.     {LPR_B50, B50, 50},
  64.     {LPR_B75, B75, 75},
  65.     {LPR_B110, B110, 110},
  66.     {LPR_B134, B134, 134},
  67.     {LPR_B150, B150, 150},
  68.     {-1, B200, 200},
  69.     {LPR_B300, B300, 300},
  70.     {LPR_B600, B600, 600},
  71.     {LPR_B1200, B1200, 1200},
  72.     {LPR_B2400, B2400, 2400},
  73.     {LPR_B4800, B4800, 4800},
  74.     {LPR_B9600, B9600, 9600}, 
  75.     {-1, -1, -1}
  76. };
  77.  
  78. /*
  79.  * Ascii values of command keys.
  80.  */
  81. #define KBD_TAB        '\t'
  82. #define KBD_DEL        127
  83. #define KBD_RET        '\r'
  84.  
  85. /*
  86.  *  Define "hardware-independent" codes for the control, shift, meta and 
  87.  *  function keys.  Codes start after the last 7-bit ASCII code (127)
  88.  *  and are assigned in an arbitrary order.
  89.  */
  90. #define KBD_NOKEY    128
  91. #define KBD_UNKNOWN    129
  92.  
  93. #define KBD_F1        201
  94. #define KBD_F2        202
  95. #define KBD_F3        203
  96. #define KBD_F4        204
  97. #define KBD_F5        205
  98. #define KBD_F6        206
  99. #define KBD_F7        207
  100. #define KBD_F8        208
  101. #define KBD_F9        209
  102. #define KBD_F10        210
  103. #define KBD_F11        211
  104. #define KBD_F12        212
  105. #define KBD_F13        213
  106. #define KBD_F14        214
  107. #define KBD_HELP    215
  108. #define KBD_DO        216
  109. #define KBD_F17        217
  110. #define KBD_F18        218
  111. #define KBD_F19        219
  112. #define KBD_F20        220
  113.  
  114. #define KBD_FIND    221
  115. #define KBD_INSERT    222
  116. #define KBD_REMOVE    223
  117. #define KBD_SELECT    224
  118. #define KBD_PREVIOUS    225
  119. #define KBD_NEXT    226
  120.  
  121. #define KBD_KP_ENTER    227
  122. #define KBD_KP_F1    228
  123. #define KBD_KP_F2    229
  124. #define KBD_KP_F3    230
  125. #define KBD_KP_F4    231
  126. #define KBD_LEFT    232
  127. #define KBD_RIGHT    233
  128. #define KBD_DOWN    234
  129. #define KBD_UP        235
  130.  
  131. #define KBD_CONTROL    236
  132. #define KBD_SHIFT    237
  133. #define KBD_CAPSLOCK    238
  134. #define KBD_ALTERNATE    239
  135.  
  136. #define KBD_MAX_VALUE    KBD_ALTERNATE
  137.  
  138. /*
  139.  * Keyboard to Ascii, unshifted. 
  140.  */
  141. static unsigned char unshiftedAscii[] = {
  142. /*  0 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  143. /*  4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  144. /*  8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  145. /*  c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  146. /* 10 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  147. /* 14 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  148. /* 18 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  149. /* 1c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  150. /* 20 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  151. /* 24 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  152. /* 28 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  153. /* 2c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  154. /* 30 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  155. /* 34 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  156. /* 38 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  157. /* 3c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  158. /* 40 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  159. /* 44 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  160. /* 48 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  161. /* 4c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  162. /* 50 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  163. /* 54 */ KBD_NOKEY,    KBD_NOKEY,    KBD_F1,        KBD_F2,
  164. /* 58 */ KBD_F3,    KBD_F4,        KBD_F5,        KBD_NOKEY,
  165. /* 5c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  166. /* 60 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  167. /* 64 */ KBD_F6,    KBD_F7,        KBD_F8,        KBD_F9,
  168. /* 68 */ KBD_F10,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  169. /* 6c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  170. /* 70 */ KBD_NOKEY,    KBD_F11,    KBD_F12,    KBD_F13,
  171. /* 74 */ KBD_F14,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  172. /* 78 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  173. /* 7c */ KBD_HELP,    KBD_DO,        KBD_NOKEY,    KBD_NOKEY,
  174. /* 80 */ KBD_F17,    KBD_F18,    KBD_F19,    KBD_F20,
  175. /* 84 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  176. /* 88 */ KBD_NOKEY,    KBD_NOKEY,    KBD_FIND,    KBD_INSERT,
  177. /* 8c */ KBD_REMOVE,    KBD_SELECT,    KBD_PREVIOUS,    KBD_NEXT,
  178. /* 90 */ KBD_NOKEY,    KBD_NOKEY,    '0',        KBD_NOKEY,
  179. /* 94 */ '.',        KBD_KP_ENTER,    '1',        '2',
  180. /* 98 */ '3',        '4',        '5',        '6',
  181. /* 9c */ ',',        '7',        '8',        '9',
  182. /* a0 */ '-',        KBD_KP_F1,    KBD_KP_F2,    KBD_KP_F3,
  183. /* a4 */ KBD_KP_F4,    KBD_NOKEY,    KBD_NOKEY,    KBD_LEFT,
  184. /* a8 */ KBD_RIGHT,    KBD_DOWN,     KBD_UP,        KBD_NOKEY,
  185. /* ac */ KBD_NOKEY,    KBD_NOKEY,    KBD_SHIFT,    KBD_CONTROL,
  186. /* b0 */ KBD_CAPSLOCK,    KBD_ALTERNATE,    KBD_NOKEY,    KBD_NOKEY,
  187. /* b4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  188. /* b8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  189. /* bc */ KBD_DEL,    KBD_RET,    KBD_TAB,    '`',
  190. /* c0 */ '1',        'q',        'a',        'z',
  191. /* c4 */ KBD_NOKEY,    '2',        'w',        's',
  192. /* c8 */ 'x',        '<',        KBD_NOKEY,    '3',
  193. /* cc */ 'e',        'd',        'c',        KBD_NOKEY,
  194. /* d0 */ '4',        'r',        'f',        'v',
  195. /* d4 */ ' ',        KBD_NOKEY,    '5',        't',
  196. /* d8 */ 'g',        'b',        KBD_NOKEY,    '6',
  197. /* dc */ 'y',        'h',        'n',        KBD_NOKEY,
  198. /* e0 */ '7',        'u',        'j',        'm',
  199. /* e4 */ KBD_NOKEY,    '8',        'i',        'k',
  200. /* e8 */ ',',        KBD_NOKEY,    '9',        'o',
  201. /* ec */ 'l',        '.',        KBD_NOKEY,    '0',
  202. /* f0 */ 'p',        KBD_NOKEY,    ';',        '/',
  203. /* f4 */ KBD_NOKEY,    '=',        ']',        '\\',
  204. /* f8 */ KBD_NOKEY,    '-',        '[',        '\'',
  205. /* fc */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  206. };
  207.  
  208. /*
  209.  * Keyboard to Ascii, shifted.
  210.  */
  211. static unsigned char shiftedAscii[] = {
  212. /*  0 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  213. /*  4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  214. /*  8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  215. /*  c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  216. /* 10 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  217. /* 14 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  218. /* 18 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  219. /* 1c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  220. /* 20 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  221. /* 24 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  222. /* 28 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  223. /* 2c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  224. /* 30 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  225. /* 34 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  226. /* 38 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  227. /* 3c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  228. /* 40 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  229. /* 44 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  230. /* 48 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  231. /* 4c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  232. /* 50 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  233. /* 54 */ KBD_NOKEY,    KBD_NOKEY,    KBD_F1,        KBD_F2,
  234. /* 58 */ KBD_F3,    KBD_F4,        KBD_F5,        KBD_NOKEY,
  235. /* 5c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  236. /* 60 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  237. /* 64 */ KBD_F6,    KBD_F7,        KBD_F8,        KBD_F9,
  238. /* 68 */ KBD_F10,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  239. /* 6c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  240. /* 70 */ KBD_NOKEY,    KBD_F11,    KBD_F12,    KBD_F13,
  241. /* 74 */ KBD_F14,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  242. /* 78 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  243. /* 7c */ KBD_HELP,    KBD_DO,        KBD_NOKEY,    KBD_NOKEY,
  244. /* 80 */ KBD_F17,    KBD_F18,    KBD_F19,    KBD_F20,
  245. /* 84 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  246. /* 88 */ KBD_NOKEY,    KBD_NOKEY,    KBD_FIND,    KBD_INSERT,
  247. /* 8c */ KBD_REMOVE,    KBD_SELECT,    KBD_PREVIOUS,    KBD_NEXT,
  248. /* 90 */ KBD_NOKEY,    KBD_NOKEY,    '0',        KBD_NOKEY,
  249. /* 94 */ '.',        KBD_KP_ENTER,    '1',        '2',
  250. /* 98 */ '3',        '4',        '5',        '6',
  251. /* 9c */ ',',        '7',        '8',        '9',
  252. /* a0 */ '-',        KBD_KP_F1,    KBD_KP_F2,    KBD_KP_F3,
  253. /* a4 */ KBD_KP_F4,    KBD_NOKEY,    KBD_NOKEY,    KBD_LEFT,
  254. /* a8 */ KBD_RIGHT,    KBD_DOWN,     KBD_UP,        KBD_NOKEY,
  255. /* ac */ KBD_NOKEY,    KBD_NOKEY,    KBD_SHIFT,    KBD_CONTROL,
  256. /* b0 */ KBD_CAPSLOCK,    KBD_ALTERNATE,    KBD_NOKEY,    KBD_NOKEY,
  257. /* b4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  258. /* b8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  259. /* bc */ KBD_DEL,    KBD_RET,    KBD_TAB,    '~',
  260. /* c0 */ '!',        'q',        'a',        'z',
  261. /* c4 */ KBD_NOKEY,    '@',        'w',        's',
  262. /* c8 */ 'x',        '>',        KBD_NOKEY,    '#',
  263. /* cc */ 'e',        'd',        'c',        KBD_NOKEY,
  264. /* d0 */ '$',        'r',        'f',        'v',
  265. /* d4 */ ' ',        KBD_NOKEY,    '%',        't',
  266. /* d8 */ 'g',        'b',        KBD_NOKEY,    '^',
  267. /* dc */ 'y',        'h',        'n',        KBD_NOKEY,
  268. /* e0 */ '&',        'u',        'j',        'm',
  269. /* e4 */ KBD_NOKEY,    '*',        'i',        'k',
  270. /* e8 */ ',',        KBD_NOKEY,    '(',        'o',
  271. /* ec */ 'l',        '.',        KBD_NOKEY,    ')',
  272. /* f0 */ 'p',        KBD_NOKEY,    ':',        '?',
  273. /* f4 */ KBD_NOKEY,    '+',        '}',        '|',
  274. /* f8 */ KBD_NOKEY,    '_',        '{',        '"',
  275. /* fc */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  276. };
  277.  
  278.  
  279. /*
  280.  * ----------------------------------------------------------------------------
  281.  *
  282.  * DevDC7085Reset --
  283.  *
  284.  *    Reset the chip.
  285.  *
  286.  * Results:
  287.  *    None.
  288.  *
  289.  * Side effects:
  290.  *    None.
  291.  *
  292.  * ----------------------------------------------------------------------------
  293.  */
  294. void
  295. DevDC7085Reset()
  296. {
  297.     *csrPtr = CSR_CLR;
  298.     while ((*csrPtr & CSR_CLR) != 0) {
  299.     }
  300.     *csrPtr = CSR_MSE | CSR_TIE | CSR_RIE;
  301. }
  302.  
  303. static void RecvIntr(), XmitIntr();
  304.  
  305. /*
  306.  * ----------------------------------------------------------------------------
  307.  *
  308.  * Dev_DC7085Interrupt --
  309.  *
  310.  *    Service an interrupt from the uart.
  311.  *
  312.  * Results:
  313.  *    None.
  314.  *
  315.  * Side effects:
  316.  *    Adds serial, keyboard or mouse events to the queue.
  317.  *
  318.  * ----------------------------------------------------------------------------
  319.  */
  320. ENTRY void
  321. Dev_DC7085Interrupt(statusReg, causeReg, pc, data)
  322.     unsigned int statusReg;
  323.     unsigned int causeReg;
  324.     Address pc;
  325.     ClientData data;
  326. {
  327.     MASTER_LOCK(&dc7085Mutex);
  328.  
  329.     if (*csrPtr & CSR_RDONE) {
  330.     RecvIntr();
  331.     }
  332.  
  333.     if (*csrPtr & CSR_TRDY) {
  334.     XmitIntr();
  335.     }
  336.  
  337.     MASTER_UNLOCK(&dc7085Mutex);
  338. }
  339.  
  340. static Boolean    shiftDown = FALSE;
  341. static Boolean    ctrlDown = FALSE;
  342. static Boolean    consoleCmd = FALSE;
  343. static unsigned char lastChar = 0;
  344. static Time    consoleCmdTime;
  345.  
  346.  
  347. /*
  348.  *----------------------------------------------------------------------
  349.  *
  350.  * RecvIntr --
  351.  *
  352.  *    Process a received character.
  353.  *
  354.  * Results:
  355.  *    None.
  356.  *
  357.  * Side effects:
  358.  *    Events added to the queue.
  359.  *
  360.  *----------------------------------------------------------------------
  361.  */
  362. ENTRY static void
  363. RecvIntr()
  364. {
  365.     unsigned short    recvBuf;
  366.     unsigned char    ch;
  367.     unsigned char    asciiChar;
  368.  
  369.     while (*csrPtr & CSR_RDONE) {
  370.     recvBuf = *rBufPtr;
  371.     ch = recvBuf & 0xFF;
  372.  
  373.     switch ((recvBuf & RBUF_LINE_NUM) >> RBUF_LINE_NUM_SHIFT) {
  374.         case KBD_PORT: {
  375.         if (devGraphicsOpen && !devDivertXInput) {
  376.             MASTER_UNLOCK(&dc7085Mutex);
  377.             DevGraphicsKbdIntr(ch);
  378.             MASTER_LOCK(&dc7085Mutex);
  379.             break;
  380.         }
  381.         if (ch != KEY_REPEAT) {
  382.             if (ch == KEY_UP) {
  383.             shiftDown = FALSE;
  384.             ctrlDown = FALSE;
  385.             break;
  386.             } else {
  387.             if (ch == KEY_SHIFT) {
  388.                 shiftDown = TRUE;
  389.                 break;
  390.             } else if (ch == KEY_CONTROL) {
  391.                 ctrlDown = TRUE;
  392.                 break;
  393.             } else if (ch == KEY_COMMAND) {
  394.                 consoleCmd = TRUE;
  395.                 Timer_GetTimeOfDay(&consoleCmdTime, (int *)NIL,
  396.                            (Boolean *)NIL);
  397.                 break;
  398.             }
  399.             }
  400.             lastChar = ch;
  401.         } else {
  402.             ch = lastChar;
  403.         }
  404.  
  405.         asciiChar = DevDC7085TranslateKey(ch, shiftDown, ctrlDown);
  406.         if (asciiChar != -1) {
  407.             if (consoleCmd) {
  408.             Time curTime, diff;
  409.  
  410.             consoleCmd = FALSE;
  411.             Timer_GetTimeOfDay(&curTime, (int *)NIL,(Boolean *)NIL);
  412.             Time_Subtract(curTime, consoleCmdTime, &diff);
  413.             if (diff.seconds <= CONSOLE_CMD_INTERVAL) {
  414.                 Dev_InvokeConsoleCmd(asciiChar);
  415.             } else {
  416.                 (*devKeyboard.inputProc)(devKeyboard.inputData, 
  417.                              asciiChar);
  418.             }
  419.             } else {
  420.             (*devKeyboard.inputProc)(devKeyboard.inputData, 
  421.                          asciiChar);
  422.             }
  423.         }
  424.         break;
  425.         }
  426.         case MOUSE_PORT:
  427.         if (devGraphicsOpen && !devDivertXInput) {
  428.             MASTER_UNLOCK(&dc7085Mutex);
  429.             DevGraphicsMouseIntr(ch);
  430.             MASTER_LOCK(&dc7085Mutex);
  431.         }
  432.         break;
  433.         case MODEM_PORT:
  434.         (*devSerialA.inputProc)(devSerialA.inputData, ch);
  435.         break;
  436.         case PRINTER_PORT:
  437.         (*devSerialB.inputProc)(devSerialB.inputData, ch);
  438.         break;
  439.     }
  440.     }
  441. }
  442.  
  443.  
  444. /*
  445.  *----------------------------------------------------------------------
  446.  *
  447.  * DevDC7085TranslateKey --
  448.  *
  449.  *    Translate a key code to an ascii character.
  450.  *
  451.  * Results:
  452.  *    The ascii character, -1 if couldn't translate it.
  453.  *
  454.  * Side effects:
  455.  *    None.
  456.  *
  457.  *----------------------------------------------------------------------
  458.  */
  459. char 
  460. DevDC7085TranslateKey(ch, shiftDown, ctrlDown)
  461.     unsigned char    ch;
  462.     Boolean    shiftDown;
  463.     Boolean    ctrlDown;
  464. {
  465.     char asciiChar;
  466.  
  467.     if (shiftDown) {
  468.     asciiChar = shiftedAscii[ch];
  469.     } else {
  470.     asciiChar = unshiftedAscii[ch];
  471.     }
  472.     if (asciiChar >= KBD_NOKEY) {
  473.     /*
  474.      * A function key was typed - ignore it.
  475.      */
  476.     return(-1);
  477.     } else if (asciiChar > KBD_MAX_VALUE) {
  478.     printf("DevDC7085TranslateKey: Bad key code raw: %d, mapped: %d\n",
  479.             ch, asciiChar);
  480.     return(-1);
  481.     } else {
  482.     if (asciiChar >= 'a' && asciiChar <= 'z') {
  483.         if (ctrlDown) {
  484.         asciiChar = asciiChar - 'a' + '';
  485.         } else if (shiftDown) {
  486.         asciiChar = asciiChar - 'a' + 'A';
  487.         }
  488.     } else if (ctrlDown) {
  489.         if (asciiChar >= '[' && asciiChar <= '_') {
  490.         asciiChar = asciiChar - '@';
  491.         } else if (asciiChar == ' ' || asciiChar == '@') {
  492.         asciiChar = '\0'; 
  493.         }
  494.     }
  495.     }
  496.  
  497.     return(asciiChar);
  498. }
  499.  
  500.  
  501. /*
  502.  *----------------------------------------------------------------------
  503.  *
  504.  * XmitIntr --
  505.  *
  506.  *    Handle a transmission interrupt.
  507.  *
  508.  * Results:
  509.  *    None.
  510.  *
  511.  * Side effects:
  512.  *    None.
  513.  *
  514.  *----------------------------------------------------------------------
  515.  */
  516. static void
  517. XmitIntr()
  518. {
  519.     char c;
  520.     int lineNum;
  521.  
  522.     if (!(*csrPtr & CSR_TRDY)) {
  523.     printf("XmitIntr: Spurious interrupt\n");
  524.     return;
  525.     }
  526.     lineNum = *csrPtr >> 8;
  527.     switch (lineNum & 0x3) {
  528.     case KBD_PORT:
  529.         break;
  530.     case MODEM_PORT:
  531.         c = (*devSerialA.outputProc)(devSerialA.outputData);
  532.         if (c == -1) {
  533.         *tcrPtr &= ~(1 << MODEM_PORT);
  534.         devSerialA.flags &= ~XMIT_ENABLED;
  535.         } else {
  536.         *tdrPtr = breakVal | c;
  537.         }
  538.         break;
  539.     case PRINTER_PORT:
  540.         c = (*devSerialB.outputProc)(devSerialB.outputData);
  541.         if (c == -1) {
  542.         *tcrPtr &= ~(1 << PRINTER_PORT);
  543.         devSerialB.flags &= ~XMIT_ENABLED;
  544.         } else {
  545.         *tdrPtr = breakVal | c;
  546.         }
  547.         break;
  548.     }
  549. }
  550.  
  551.  
  552. /*
  553.  *----------------------------------------------------------------------
  554.  *
  555.  * DevDC7085Activate --
  556.  *
  557.  *    This procedure is invoked in order to "activate" one half of a
  558.  *    DC7085 chip.
  559.  *
  560.  * Results:
  561.  *    None.
  562.  *
  563.  * Side effects:
  564.  *    The channel is re-initialized and the receiver is started.
  565.  *
  566.  *----------------------------------------------------------------------
  567.  */
  568. ENTRY void
  569. DevDC7085Activate(dcPtr)
  570.     register DevDC7085 *dcPtr;        /* Information about the device. */
  571. {
  572.     MASTER_LOCK(&dc7085Mutex);
  573.  
  574.     switch (dcPtr->port) {
  575.     case KBD_PORT:
  576.         if (!(dcPtr->flags & LINE_ACTIVE)) {
  577.         *lprPtr = LPR_RXENAB | LPR_B4800 | LPR_8_BIT_CHAR | KBD_PORT;
  578.         dcPtr->flags |= LINE_ACTIVE;
  579.         }
  580.         break;
  581.     case MODEM_PORT:
  582.     case PRINTER_PORT:
  583.         if (!(dcPtr->flags & LINE_ACTIVE)) {
  584.         *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) | 
  585.                  LPR_8_BIT_CHAR | dcPtr->port;
  586.         dcPtr->flags |= LINE_ACTIVE;
  587.         }
  588.         break;
  589.     }
  590.  
  591.     MASTER_UNLOCK(&dc7085Mutex);
  592. }
  593.  
  594.  
  595. /*
  596.  *----------------------------------------------------------------------
  597.  *
  598.  * DevDC7085RawProc --
  599.  *
  600.  *    This procedure is called back from the Td module as a raw
  601.  *    control procedure.
  602.  *
  603.  * Results:
  604.  *    The return value is the number of bytes returned to the caller
  605.  *    at outBuffer.
  606.  *
  607.  * Side effects:
  608.  *    Depends on the control operation.  Most likely effect is to
  609.  *    start transferring output data.
  610.  *
  611.  *----------------------------------------------------------------------
  612.  */
  613.  
  614. /* ARGSUSED */
  615. ENTRY int
  616. DevDC7085RawProc(dcPtr, operation, inBufSize, inBuffer, outBufSize, outBuffer)
  617.     register DevDC7085 *dcPtr;    /* Our information about device. */
  618.     int operation;        /* What to do:  TD_RAW_OUTPUT_READY etc. */
  619.     int inBufSize;        /* Size of input buffer for operation. */
  620.     char *inBuffer;        /* Input buffer. */
  621.     int outBufSize;        /* Size of output buffer for operation. */
  622.     char *outBuffer;        /* Output buffer. */
  623. {
  624.     int result = 0;
  625.  
  626.     MASTER_LOCK(&dc7085Mutex);
  627.  
  628.     switch (operation) {
  629.     case TD_RAW_START_BREAK:
  630.         breakVal |= 1 << (dcPtr->port + 8);
  631.         *tdrPtr = breakVal;
  632.         break;
  633.  
  634.     case TD_RAW_STOP_BREAK:
  635.         breakVal &= ~(1 << (dcPtr->port + 8));
  636.         *tdrPtr = breakVal;
  637.         break;
  638.  
  639.     case TD_RAW_SET_DTR:
  640.         if (dcPtr->port == MODEM_PORT) {
  641.         *tcrPtr |= TCR_DTR2;
  642.         }
  643.         break;
  644.  
  645.     case TD_RAW_CLEAR_DTR:
  646.         if (dcPtr->port == MODEM_PORT) {
  647.         *tcrPtr &= ~TCR_DTR2;
  648.         }
  649.         break;
  650.  
  651.     case TD_RAW_SHUTDOWN:
  652.         if (dcPtr->flags & LINE_ACTIVE) {
  653.         *lprPtr = dcPtr->port;
  654.         dcPtr->flags &= ~LINE_ACTIVE;
  655.         *tcrPtr &= ~(1 << dcPtr->port);
  656.         }
  657.         break;
  658.  
  659.     case TD_RAW_OUTPUT_READY:
  660.         if (!(dcPtr->flags & XMIT_ENABLED)) {
  661.         *tcrPtr |= 1 << dcPtr->port;
  662.         dcPtr->flags |= XMIT_ENABLED;
  663.         }
  664.         break;
  665.  
  666.     case TD_RAW_FLUSH_OUTPUT:
  667.         while ((*dcPtr->outputProc)(dcPtr->outputData) != -1) {
  668.         /* do nothing */
  669.         }
  670.         break;
  671.  
  672.     case TD_RAW_FLOW_CHARS:
  673.         /* Ignore flow-control chars. */
  674.         break;
  675.  
  676.     case TD_RAW_SET_BAUD_RATE: {
  677.         Td_BaudRate *brPtr;
  678.         int        i;
  679.  
  680.         /*
  681.          * Map the baud rate from an sgttyb constant to an actual
  682.          * number.  Return the value we actually set things to.
  683.          */
  684.  
  685.         brPtr = (Td_BaudRate *) inBuffer;
  686.         for (i = 0; baudMap[i].baud != -1; i++) {
  687.         if (baudMap[i].sgttybVal == brPtr->ospeed) {
  688.             dcPtr->baud = baudMap[i].baud;
  689.             break;
  690.         }
  691.         }
  692.         switch (dcPtr->port) {
  693.         case MODEM_PORT:
  694.             *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) | 
  695.                  LPR_8_BIT_CHAR | MODEM_PORT;
  696.             break;
  697.         case PRINTER_PORT:
  698.             *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) |
  699.                  LPR_8_BIT_CHAR | PRINTER_PORT;
  700.             break;
  701.         }
  702.  
  703.         /*
  704.          * Fall through to next arm of case to return current
  705.          * settings.
  706.          */
  707.     }
  708.  
  709.     case TD_RAW_GET_BAUD_RATE: {
  710.         int i;
  711.         Td_BaudRate *brPtr;
  712.  
  713.         brPtr = (Td_BaudRate *) outBuffer;
  714.         if (outBufSize >= sizeof(Td_BaudRate)) {
  715.         for (i = 0; baudMap[i].baud != -1; i++) {
  716.             if (baudMap[i].baud == dcPtr->baud) {
  717.             brPtr->ispeed = brPtr->ospeed = baudMap[i].sgttybVal;
  718.             result = sizeof(Td_BaudRate);
  719.             }
  720.         }
  721.         }
  722.         break;
  723.     }
  724.     }
  725.     MASTER_UNLOCK(&dc7085Mutex);
  726.     return result;
  727. }
  728.  
  729.  
  730. /*
  731.  *----------------------------------------------------------------------
  732.  *
  733.  * BaudToReg --
  734.  *
  735.  *    Map from a raw baud rate to the value to shove into the register.
  736.  *
  737.  * Results:
  738.  *    The baud value to shove into the register.
  739.  *
  740.  * Side effects:
  741.  *    None.
  742.  *
  743.  *----------------------------------------------------------------------
  744.  */
  745. int
  746. BaudToReg(baud)
  747.     int    baud;
  748. {
  749.     int    i = 0;
  750.  
  751.     while (baudMap[i].baud != baud && baudMap[i].baud != -1) {
  752.     i++;
  753.     }
  754.     return(baudMap[i].regVal);
  755. }
  756.  
  757.  
  758. /*
  759.  * ----------------------------------------------------------------------------
  760.  *
  761.  * DevDC7085MouseInit --
  762.  *
  763.  *    Initialize the mouse.
  764.  *
  765.  * Results:
  766.  *    None.
  767.  *
  768.  * Side effects:
  769.  *    The mouse is initialized.
  770.  *
  771.  * ----------------------------------------------------------------------------
  772.  */
  773. ENTRY void
  774. DevDC7085MouseInit()
  775. {
  776.     MASTER_LOCK(&dc7085Mutex);
  777.  
  778.     *lprPtr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | LPR_PARENB |
  779.                LPR_8_BIT_CHAR | MOUSE_PORT;
  780.  
  781.     Mach_SetIOHandler(7, Dev_DC7085Interrupt, (ClientData) NIL);
  782.     MASTER_UNLOCK(&dc7085Mutex);
  783. }
  784.  
  785.  
  786. /*
  787.  * ----------------------------------------------------------------------------
  788.  *
  789.  * DevDC7085MousePutCh --
  790.  *
  791.  *    Write a character to the mouse.  This is only called at initialization
  792.  *    time.
  793.  *
  794.  * Results:
  795.  *    None.
  796.  *
  797.  * Side effects:
  798.  *    A character is written to the mouse.
  799.  *
  800.  * ----------------------------------------------------------------------------
  801.  */
  802. ENTRY void
  803. DevDC7085MousePutCh(c)
  804.     int    c;
  805. {
  806.     register    int    timeout;
  807.     register    int    reg;
  808.  
  809.     MASTER_LOCK(&dc7085Mutex);
  810.  
  811.     reg = *tcrPtr;
  812.     *tcrPtr = 0x2;
  813.     timeout = 60000;
  814.  
  815.     for (timeout = 60000;
  816.      (!(*csrPtr & CSR_TRDY) || (*csrPtr & CSR_TX_LINE_NUM) != 0x100) &&
  817.          timeout > 0;
  818.      timeout--) {
  819.     }
  820.     *tdrPtr = c & 0xff;
  821.     MACH_DELAY(50000);
  822.     *tcrPtr = reg;
  823.  
  824.     MASTER_UNLOCK(&dc7085Mutex);
  825. }
  826.  
  827.  
  828. /*
  829.  * ----------------------------------------------------------------------------
  830.  *
  831.  * DevDC7085MouseGetCh --
  832.  *
  833.  *    Read a character from the mouse.  This is only called at
  834.  *    initialization time.
  835.  *
  836.  * Results:
  837.  *    A character read from the mouse, -1 if we timed out waiting.
  838.  *
  839.  * Side effects:
  840.  *    None.
  841.  *
  842.  * ----------------------------------------------------------------------------
  843.  */
  844. ENTRY int
  845. DevDC7085MouseGetCh()
  846. {
  847.     register int        timeout;
  848.     register unsigned short    c;
  849.  
  850.     MASTER_LOCK(&dc7085Mutex);
  851.  
  852.     for (timeout = 1000000; timeout > 0; timeout--) {
  853.     if (*csrPtr & CSR_RDONE) {
  854.         c = *rBufPtr;
  855.         MACH_DELAY(50000);
  856.         if (((c >> 8) & 03) != 1) {
  857.         continue;
  858.         }
  859.         MASTER_UNLOCK(&dc7085Mutex);
  860.         return(c & 0xff);
  861.     }
  862.     }
  863.     MASTER_UNLOCK(&dc7085Mutex);
  864.  
  865.     return(-1);
  866. }
  867.  
  868.  
  869. /*
  870.  * ----------------------------------------------------------------------------
  871.  *
  872.  * DevDC7085KBDPutc --
  873.  *
  874.  *    Put a character out to the keyboard.
  875.  *
  876.  * Results:
  877.  *    None.
  878.  *
  879.  * Side effects:
  880.  *    A character is written to the keyboard.
  881.  *
  882.  * ----------------------------------------------------------------------------
  883.  */
  884. ENTRY void
  885. DevDC7085KBDPutc(c)
  886.     register int c;
  887. {
  888.     register unsigned    short    tcr;
  889.     register int    timeout;
  890.     int            line;
  891.  
  892.     MASTER_LOCK(&dc7085Mutex);
  893.  
  894.     tcr = *tcrPtr & 1;
  895.     *tcrPtr |= 1;
  896.     while (1) {
  897.         timeout = 1000000;
  898.         while (!(*csrPtr & CSR_TRDY) && timeout > 0) {
  899.             timeout--;
  900.         }
  901.         if (timeout == 0) {
  902.             break;
  903.         }
  904.         line = (*csrPtr >> 8) & 3;
  905.         if (line != 0) {
  906.             tcr |= 1 << line;
  907.             *tcrPtr &= ~(1 << line);
  908.             continue;
  909.         }
  910.         *tdrPtr = breakVal | (c & 0xff);
  911.         MACH_DELAY(5);
  912.         while (1) {
  913.             while (!(*csrPtr & CSR_TRDY)) {
  914.             }
  915.             line = (*csrPtr >> 8) & 3;
  916.             if (line != 0) {
  917.                 tcr |= 1 << line;
  918.                 *tcrPtr &= ~(1 << line);
  919.                 continue;
  920.             }
  921.             break;
  922.         }
  923.         break;
  924.     }
  925.     *tcrPtr &= ~1;
  926.     if (tcr != 0) {
  927.     *tcrPtr |= tcr;
  928.     }
  929.  
  930.     MASTER_UNLOCK(&dc7085Mutex);
  931. }
  932.  
  933.